//基础设置类，其中作为初始化获取base对象，中间包括光照相机等对象，地图，地址url等属性
import { getStream } from '../Core/connect'
import * as MathUtils from '../Math/MathUtils'

export class Base {
    //base对象，中景应该包括光照时间天气大气层等
    lightIntensity: string
    lightColor:string
    uuid: string
    constructor() {
        this.uuid = MathUtils.generateUUID()
        this.lightIntensity = ''
        this.lightColor = ''
    }

    getBaseData(){
        //完成视频流链接之后
        return new Promise(function(resolve){
            const stream = getStream()
            const sessionId = MathUtils.generateUUID()
            const message = { baseFunction: 'getBase',sessionId: sessionId }
            stream.emitUIInteraction(message)
            const getBaseDataReady = (data: string) => {
                console.log(data)
                const returnData = JSON.parse(data)
                if (returnData.sessionId === sessionId) {
                    resolve(returnData)
                    stream.removeResponseEventListener("getBaseDataReady")
                }
            }
            stream.addResponseEventListener("getBaseDataReady", getBaseDataReady)
        })
    }

    //光照设置方法
    setLighIntensity(Intensity:number){
        const stream = getStream()
        const str = {baseFunction: 'setLight', Option:{function:'setLightIntensity',Intensity:Intensity}}
        stream.emitUIInteraction(str)
    }
    setLighColor(Color:UEColor){
        const stream = getStream()
        const str = {baseFunction: 'setLight', Option:{function:'setLightColor',Color:Color}}
        stream.emitUIInteraction(str)
    }

     //设置光照时间
     SetLightTime(SolarTime:number){
        const stream = getStream()
        const str = {baseFunction: 'setLight', Option:{function:'SetLightTime',SolarTime:SolarTime}}
        stream.emitUIInteraction(str)
    }

    //瑞丽散射设置方法
    setRayleighScatteringScale(RayleighScatteringScale:number){
        //瑞利散射范围
        const stream = getStream()
        const str = {baseFunction: 'setAtmosphere', Option:{function:'setRayleighScatteringScale',RayleighScatteringScale:RayleighScatteringScale}}
        stream.emitUIInteraction(str)
    }
    setRayleighScattering(RayleighScattering:UEColor){
        //瑞丽散射颜色
        const stream = getStream()
        const str = {baseFunction: 'setAtmosphere', Option:{function:'setRayleighScattering',RayleighScattering:RayleighScattering}}
        stream.emitUIInteraction(str)
    }
    setRayleighExponentialDistribution(RayleighExponentialDistribution:number){
        //瑞丽指数分布
        const stream = getStream()
        const str = {baseFunction: 'setAtmosphere', Option:{function:'setRayleighExponentialDistribution',RayleighExponentialDistribution:RayleighExponentialDistribution}}
        stream.emitUIInteraction(str)
    }
    // 隐藏地球
    hiddenEarth(){
       const stream = getStream()
       const str = {baseFunction: 'hiddenEarth'}
       stream.emitUIInteraction(str)
   }
   // 显示地球
   showEarth(){
      const stream = getStream()
      const str = {baseFunction: 'showEarth'}
      stream.emitUIInteraction(str)
  }
}